<?php ob_start(); ?>
<link rel="stylesheet" href="/css/admin.css">
<script src="/js/admin.js"></script>

<div class="admin-container">
    <button id="showAddFormBtn">添加书签</button>
    <button id="showBookmarksListBtn">列出所有书签</button>

    <div id="addBookmarkForm" style="display:none;">
        <h2>添加书签</h2>
        <form action="index.php?action=add_bookmark" method="post" class="admin-form">
            <input type="text" name="title" placeholder="标题" required>
            <input type="url" name="url" placeholder="URL" required>
            <input type="text" name="category" placeholder="分类">
            <textarea name="description" placeholder="描述"></textarea>
            <input type="text" name="imgurl" placeholder="图片url">
            <button type="submit">添加书签</button>
        </form>
    </div>

    <div id="bookmarksList" style="display:none;">
        <h2>所有书签</h2>
        <table>
            <tr>
                <th>标题</th>
                <th>URL</th>
                <th>分类</th>
                <th>操作</th>
            </tr>
            <?php
            $bookmarks = $bookmarkController->getAll(); // 假设已有方法获取所有书签
            foreach ($bookmarks as $bookmark):
            ?>
            <tr>
                <td><?php echo htmlspecialchars($bookmark['title']); ?></td>
                <td><?php echo htmlspecialchars($bookmark['url']); ?></td>
                <td><?php echo htmlspecialchars($bookmark['category']); ?></td>
                <td class="action-btns">
                    <button onclick="window.location.href='index.php?action=edit_bookmark&id=<?php echo $bookmark['id']; ?>'">编辑</button>
                    <button class="delete-btn" onclick="if(confirm('确定要删除吗？')) window.location.href='index.php?action=delete_bookmark&id=<?php echo $bookmark['id']; ?>'">删除</button>
                </td>

            </tr>
            <?php endforeach; ?>
        </table>
    </div>
</div>
<?php $content = ob_get_clean(); ?>
<?php include 'layout.php'; ?>
